package modul.pencatatan.datapeminjam;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class PeminjamTabelModel extends AbstractTableModel {

    private List<Peminjam> isi = new ArrayList<Peminjam>();

    public void tambahDVDVCD(Peminjam pj) {
        isi.add(pj);
        fireTableRowsInserted(getRowCount(), getColumnCount());
    }

    public void hapusTabel(int i, int row) {
        isi.remove(i);
        fireTableRowsDeleted(i, row);
    }

    public Peminjam getDvdVcd(int index) {
        return (Peminjam) isi.get(index);
    }

    @Override
    public int getRowCount() {
        return isi.size();
    }

    @Override
    public int getColumnCount() {
        return 8;
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Nama Peminjam";
            case 2:
                return "Tempat Lahir";
            case 3:
                return "Tanggal Lahir";
            case 4:
                return "Jenis ID";
            case 5:
                return "No. ID";
            case 6:
                return "Telepon";
            case 7:
                return "Alamat";
            default:
                return null;
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return isi.get(rowIndex).getIdPeminjam();
            case 1:
                return isi.get(rowIndex).getNamaPeminjam();
            case 2:
                return isi.get(rowIndex).getTempatLahir();
            case 3:
                return isi.get(rowIndex).getTglLahir();
            case 4:
                return isi.get(rowIndex).getJenisID();
            case 5:
                return isi.get(rowIndex).getNoId();
            case 6:
                return isi.get(rowIndex).getTelepon();
            case 7:
                return isi.get(rowIndex).getAlamat();
            default:
                return null;
        }
    }
}